<?
// JavaScript functions
// Based on the WebCMSv1 Library
// Written by John Shepherd, Aug 2004
// Updated by John Shepherd, May 2005
// Each function here returns the text of a JavaScript fucntion
// They are intended to be used as arguments to startPage(),
// which places JavaScript functions in the page <head>..</head>

# jsConfirmDel: check whether a form to delete should be submitted
function jsConfirmDel()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function confirmDel()
{
	return confirm('Are you sure you want to delete?');
}
</script>
JAVASCRIPT;
}

# jsConfirmDelA: check whether a link should be followed
function jsConfirmDelA()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function confirmDelA(url)
{
	if (confirm('Are you sure you want to delete?')) location.href = url;
}
</script>
JAVASCRIPT;
}

# jsPopup: JavaScript to produce a smallish pop-up window
function jsPopup()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function popup(url)
{
	window.open(url,'_popup',
		'width=400,height=300,scrollbars=yes,resizeable=yes');
	return false;
}
</script>
JAVASCRIPT;
}

function jsCheckAllFilled()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function checkAllFilled(form) {
	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].value == '') {
			alert('Please fill out ALL fields.')
			return false
		}
	}
	return true
}
</script>
JAVASCRIPT;
}

function jsCheckAllBoxes()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function checkAllBoxes(form)
{
	var val = form.elements[0].checked;
	for (var i = 1; i < form.elements.length; i++)
		form.elements[i].checked = val
}
</script>
JAVASCRIPT;
}

function jsCheckOneChecked()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function checkOneChecked(form,act,mesg)
{
	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].checked) {
			if (act == "del")
				return confirmDel()
			else
				return true
		}
		else
			continue
	}
	alert(mesg)
	return false
}
</script>
JAVASCRIPT;
}

function jsCheckDate()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function checkDate(cdate,month)
{
	var date = parseInt(cdate)
	var maxDate;
	if ((month == 'Jan') || (month == 'Mar') || (month == 'May') || (month == 'Jul') || (month == 'Aug') || (month == 'Oct') || (month == 'Dec')) {
		maxDate = 31
	}
	if ((month == 'Apr') || (month == 'Jun') || (month == 'Sep') || (month == 'Nov')) {
		maxDate = 30
	}
	if (month == 'Feb') {
		if (isLeapYear()) {
			maxDate = 29
		}
		else {
			maxDate = 28
		}
	}
	if ((date <= 0) || (date > maxDate)) {
		alert('Choose date between 1 .. '+maxDate)
		return false
	}
	return true
}
function isLeapYear()
{
	var today = new Date()
	var thisYear = today.getYear()
	if ((((thisYear % 4) == 0) && ((thisYear % 100) != 0)) || ((thisYear % 400) == 0) )
		return true
	else return false
}
</script>
JAVASCRIPT;
}

function jsIsNumber()
{
return <<<JAVASCRIPT
<script type='text/javascript'>
function isNumber(inputVal,name) {
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (oneChar < '0' || oneChar > '9') {
			alert(name + ' should be in numbers.')
			return false
		}
	}
	return true
}
</script>
JAVASCRIPT;
}

function jsToggleAddInput()
{
$url = URL."/lib/forms";
return <<<JAVASCRIPT
<script type="text/javascript" src="$url/toggle.js"></script>
</script>
JAVASCRIPT;
}

function jsLinkedSelect()
{
$url = URL."/lib/forms";
return <<<JAVASCRIPT
<script type="text/javascript" src="$url/linked.js"></script>
</script>
JAVASCRIPT;
}

function jsUseCalendar()
{
$url = URL."/lib/cal";
return <<<JAVASCRIPT
<link rel="stylesheet" type="text/css" href="$url/cal.css"/>
<script type="text/javascript" src="$url/calendar.js"></script>
<script type="text/javascript" src="$url/lang/calendar-en.js"></script>
<script type="text/javascript" src="$url/setup.js"></script>
JAVASCRIPT;
}

function jsShowHide()
{
return <<<JAVASCRIPT
<script language="JavaScript">
function changeText(el, newText) {
  // Safari work around
  if (el.innerText)
    el.innerText = newText;
  else if (el.firstChild && el.firstChild.nodeValue)
    el.firstChild.nodeValue = newText;
}
function toggleVisible(elid) {
  el1 = document.getElementById("a"+elid);
  el2 = document.getElementById("b"+elid);
  if (el1.style.display == "") {
     el1.style.display = "none";
     changeText(el2,"show detail");
  }
  else {
     el1.style.display = "";
     changeText(el2,"hide detail");
  }
}
</script>
JAVASCRIPT;
}

?>
